package com.dlry.web.valid;

import java.text.ParseException;
import java.text.SimpleDateFormat;

import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;

import com.dlry.entity.DlTravelRequest;

public class TravelForm {
	private static final String reg = "((^((1[8-9]\\d{2})|([2-9]\\d{3}))([-\\/\\._])(10|12|0?[13578])([-\\/\\._])(3[01]|[12][0-9]|0?[1-9])$)|(^((1[8-9]\\d{2})|([2-9]\\d{3}))([-\\/\\._])(11|0?[469])([-\\/\\._])(30|[12][0-9]|0?[1-9])$)|(^((1[8-9]\\d{2})|([2-9]\\d{3}))([-\\/\\._])(0?2)([-\\/\\._])(2[0-8]|1[0-9]|0?[1-9])$)|(^([2468][048]00)([-\\/\\._])(0?2)([-\\/\\._])(29)$)|(^([3579][26]00)([-\\/\\._])(0?2)([-\\/\\._])(29)$)|(^([1][89][0][48])([-\\/\\._])(0?2)([-\\/\\._])(29)$)|(^([2-9][0-9][0][48])([-\\/\\._])(0?2)([-\\/\\._])(29)$)|(^([1][89][2468][048])([-\\/\\._])(0?2)([-\\/\\._])(29)$)|(^([2-9][0-9][2468][048])([-\\/\\._])(0?2)([-\\/\\._])(29)$)|(^([1][89][13579][26])([-\\/\\._])(0?2)([-\\/\\._])(29)$)|(^([2-9][0-9][13579][26])([-\\/\\._])(0?2)([-\\/\\._])(29)$))";
	@Pattern(regexp = reg, message = "日期格式不正确")
	private String fromTime;
	@Pattern(regexp = reg, message = "日期格式不正确")
	private String toTime;
	@Size(min = 2, max = 100, message = "至少2个字，最多100个字")
	private String reason;
	@Size(min = 2, max = 10, message = "至少2个字，最多10个字")
	private String locale;

	public String getFromTime() {
		return fromTime;
	}

	public void setFromTime(String fromTime) {
		this.fromTime = fromTime;
	}

	public String getToTime() {
		return toTime;
	}

	public void setToTime(String toTime) {
		this.toTime = toTime;
	}

	public String getReason() {
		return reason;
	}

	public void setReason(String reason) {
		this.reason = reason;
	}

	public String getLocale() {
		return locale;
	}

	public void setLocale(String locale) {
		this.locale = locale;
	}

	public DlTravelRequest toDlTravelRequest() throws ParseException {
		DlTravelRequest travel = new DlTravelRequest();
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		travel.setFromTime(format.parse(fromTime));
		travel.setToTime(format.parse(toTime));
		travel.setReason(reason);
		travel.setLocale(locale);
		return travel;
	}

}
